home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / std / c++ / 195 < prev    next >
Encoding:
Internet Message Format  |  1996-08-06  |  1.6 KB

  1. From: ball@eng.sun.com (Mike Ball)
  2. Message-ID: <4eo5gl$rik@engnews2.Eng.Sun.COM>
  3. X-Original-Date: 31 Jan 1996 16:31:17 GMT
  4. Path: in1.uu.net!bounce-back
  5. Date: 31 Jan 96 22:10:04 GMT
  6. Approved: fjh@cs.mu.oz.au
  7. Newsgroups: comp.std.c++
  8. Subject: Re: Incompatibility C++ <-> ANSI-C
  9. Organization: Sun Microsystems Inc.
  10. References: <4ekpnj$h7q@fsuj01.rz.uni-jena.de>
  11. Reply-To: ball@eng.sun.com
  12. X-Auth: PGPMoose V1.1 PGP comp.std.c++
  13.     iQBFAgUBMQ/o4eEDnX0m9pzZAQFmkQF+NoBckBu+CQgG/HGwZSsQBW1C5yOWc7DE
  14.     rEKJHrOefFiJRlklzrts8KyU756LYlcL
  15.     =9ETv
  16.  
  17. In article h7q@fsuj01.rz.uni-jena.de, mkt@isun04.inf.uni-jena.de
  18. (Tilo Koerbs) writes:
  19. > Does the operator ?: an itegral promotion on its
  20. > second and third operand in C++?
  21. > I cannot find the answer in the ARM. (I think it says: no)
  22. > Consider this:
  23. > char x, y;
  24. > Which type has the following expression:
  25. > (a ? x : y)
  26. > In ANSI-C the type is clearly an 'int' (or 'unsigned').
  27. > But the type in C++ is 'char'???
  28. > Even different compilers have different results!
  29. > (Borland 3.1: 'char', SPARCompiler 4.0: 'int')
  30.  
  31. Not in any version of SPARCompiler C++ that I have access to, which is
  32. all of those from 4.0.1 on.  The result is clearly "char".  I don't
  33. have a 4.0 version to check.
  34.  
  35. The test was
  36.  
  37. extern "C" printf(const char*, ...);
  38. int i;
  39. int main()
  40. {
  41.     char a = 0;
  42.     char b = 0;
  43.     printf("%d\n", sizeof(i ? a : b));
  44.     return 0;
  45. }
  46.  
  47. the result was "1"
  48.  
  49. -Mike-
  50. ---
  51. [ comp.std.c++ is moderated.  Submission address: std-c++@ncar.ucar.edu.
  52.   Contact address: std-c++-request@ncar.ucar.edu.  The moderation policy
  53.   is summarized in http://dogbert.lbl.gov/~matt/std-c++/policy.html. ]
  54.